<template>
  <div>
    <FilterTable
      ref="table"
      :columns="columns"
      :dataSource="list"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
      columnsRef="xkwxlxTable"
    >
      <template slot="controls" slot-scope>
        <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle">新增</el-button> -->
      </template>
    </FilterTable>

    <BaseDialog :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Change :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { authority } from '@/utils/authMixin';
import { searchRepairType } from '@/api/repair/repair/types/index';
import Change from './change';
import { dictionary } from '@/utils/dictMixin';

export default {
  name: 'repairType',
  components: {
    Change
  },
  mixins: [dictionary, authority],
  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑' };
    return {
      fetchApi: searchRepairType, // 调用接口
      fetchParams: { xhrAbort: false },
      list: [],
      visible: false,
      columns: this.createTableColumns(),
      rowData: {},
      dialogTitle: '',
      handleType: '',
      formData: ''
    };
    console.log(fetchParams);
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    // console.log('页面不具备的权限：', this.auths);
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '操作',
        //   dataIndex: 'column-action',
        //   width: 100,
        //   render: (props, h) => {
        //     return (
        //       <div>
        //         <el-button
        //           size="mini"
        //           type="text"
        //           icon="el-icon-edit-outline"
        //           disabled={props.row.OEM_TAG == 10451002}
        //           onClick={() => {
        //             this.editHandle(props.row);
        //           }}
        //         >
        //           编辑
        //         </el-button>
        //       </div>
        //     );
        //   }
        // },
        {
          title: '维修类型代码',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filter:true,
          filterType:'input',
          editable:false,
          showOverflowTooltip: true
        },
        {
          title: '维修类型名称',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true,
          filter:true,
          filterType:'input',
          showOverflowTooltip: true
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_NAME',
          sorter: true,
          filter:true,
          filterType:'input',
          showOverflowTooltip: true
        },
        {
          title: '数据来源',
          dataIndex: 'OEM_TAG',
          sorter: true,
          filter:true,
          filterType:'input',
          showOverflowTooltip: true,
          render: props => {
            return <span>{this.createDictText(props.row.OEM_TAG, '1045')}</span>;
          }
        },
        {
          title: '是否保险',
          dataIndex: 'IS_INSURANCE',
          filter:true,
          filterType:'input',
          sorter: true,
          render: props => {
            let val = this.ischange(props.row.IS_INSURANCE) === 1 ? true : false;
            return <el-checkbox disabled value={val} onInput={val => (props.row.IS_INSURANCE = val ? 1 : 0)}></el-checkbox>;
          }
        },
        {
          title: '是否系统保留',
          dataIndex: 'IS_RESERVED',
          sorter: true,
          filter:true,
          filterType:'input',
          render: props => {
            let val = this.ischange(props.row.IS_RESERVED) === 1 ? true : false;
            return <el-checkbox disabled value={val} onInput={val => (props.row.IS_RESERVED = val ? 1 : 0)}></el-checkbox>;
          }
        },
        // {
        //   title: '是否售前维修',
        //   dataIndex: 'IS_PRE_SERVICE',
        //   width: 150,
        //   sorter: true,
        //   filter:true,
        //   filterType:'input',
        //   render: props => {
        //     let val = this.ischange(props.row.IS_PRE_SERVICE) === 1 ? true : false;
        //     return <el-checkbox disabled value={val} onInput={val => (props.row.IS_PRE_SERVICE = val ? 1 : 0)}></el-checkbox>;
        //   }
        // },
        // {
        //   title: '是否钣喷',
        //   dataIndex: 'IS_SPRAY_LABOUR',
        //   width: 150,
        //   sorter: true,
        //   filter:true,
        //   editable: false,
        //   filterType:'input',
        //   render: props => {
        //     let val = this.ischange(props.row.IS_SPRAY_LABOUR) === 1 ? true : false;
        //     return <el-checkbox disabled value={val} onInput={val => (props.row.IS_SPRAY_LABOUR = val ? 1 : 0)}></el-checkbox>;
        //   }
        // },
        {
          title: '是否有效',
          dataIndex: 'IS_VALID',
          sorter: true,
          filter:true,
          filterType:'input',
          render: props => {
            let val = this.ischange(props.row.IS_VALID) === 1 ? true : false;
            return <el-checkbox disabled value={val} onInput={val => (props.row.IS_VALID = val ? 1 : 0)}></el-checkbox>;
          }
        }
      ];
    },
    // 对后台取出来的值进行转换
    ischange(sql) {
      if (sql == 10041001) {
        return 1;
      } else {
        return 0;
      }
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    showHandler() {
      this.dialogTitle = `${this.conf[this.handleType]}维修类型`;
      this.visible = true;
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less"></style>
